﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;

public partial class Admin_SystemCycle_MonthDate_Add : System.Web.UI.Page
{
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindDropDownListYear(this.drpYear);
            if (this.drpYear.Items.Count > 0)
            {
                bindDropDownListQuarter(this.drpYear, this.drpQuarterName);
            }
        }
    }

    /// <summary>
    /// 绑定年份DropDownList
    /// </summary>
    /// <param name="_drp">绑定的控件</param>
    /// <author>grokyao</author>
    /// <date>2009-1-12</date>
    void bindDropDownListYear(DropDownList _drp)
    {
        for (int i = 2009; i <= 2100; i++)
        {
            ListItem li = new ListItem(i.ToString());
            li.Value = i.ToString();
            _drp.Items.Add(li);
        }
        string _year = Utility.HttpHelp.getParamsString("Year");
        this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));
    }

    /// <summary>
    /// 根据年份绑定年周期DropDownList
    /// </summary>
    /// <param name="_drpYear">年份DropDownList</param>
    /// <param name="_drpQuarter">年周期DropDownList</param>
    void bindDropDownListQuarter(DropDownList _drpYear,DropDownList _drpQuarter)
    {
        object[] _value = new object[1];
        _value[0] = _drpYear.SelectedValue;
        DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
        if (_quarter.Rows.Count != 0)
        {
            _drpQuarter.DataSource = _quarter;
            _drpQuarter.DataTextField = "QuarterName";
            _drpQuarter.DataValueField = "Quarter_Id";
            _drpQuarter.DataBind();
        }
        else
        {
            ListItem li = new ListItem("无年周期");
            _drpQuarter.Items.Clear();
            _drpQuarter.Items.Add(li);
        }
        string _quarterName = Utility.HttpHelp.getParamsString("Quarter");
        this.drpQuarterName.SelectedIndex = this.drpQuarterName.Items.IndexOf(this.drpQuarterName.Items.FindByValue(_quarterName));
    }

    /// <summary>
    /// 添加月周期事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-1-13</date>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        object[] _value = new object[5];
        _value[0] = this.drpYear.SelectedValue;
        _value[1] = this.drpQuarterName.SelectedItem.Text;
        _value[2] = this.txtMonthName.Text;
        _value[3] = Convert.ToDateTime(this.txtStartDate.Text);
        _value[4] = Convert.ToDateTime(this.txtEndDate.Text);
        int result = dllMonthDateManager.add(_value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("添加月周期未成功，请重试！");
        }
        else
        {
            Response.Redirect("SystemCycleManager.aspx");
        }
    }


    /// <summary>
    /// 根据年份改变年周期事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-1-13</date>
    protected void drpYeare_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownListQuarter(this.drpYear, this.drpQuarterName);
    }


    /// <summary>
    /// 重置方法
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReset_Click(object sender, EventArgs e)
    {
        this.txtEndDate.Text = "";
        this.txtMonthName.Text = "";
        this.txtStartDate.Text = "";
        
    }
}
